package com.business.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.business.common.core.domain.entity.SysDept;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.business.common.annotation.Log;
import com.business.common.core.controller.BaseController;
import com.business.common.core.domain.AjaxResult;
import com.business.common.enums.BusinessType;
import com.business.exam.domain.ExamQbCategory;
import com.business.exam.service.IExamQbCategoryService;
import com.business.common.utils.poi.ExcelUtil;

/**
 * 题库分类Controller
 *
 * @author zhanglele
 * @date 2023-11-11
 */
@Api("题库分类")
@RestController
@RequestMapping("/questionbank/category")
public class ExamQbCategoryController extends BaseController
{
    @Autowired
    private IExamQbCategoryService examQbCategoryService;

    /**
     * 获取题库分类树列表
     */
   // @PreAuthorize("@ss.hasPermi('questionbank:category:index')")
    @GetMapping("/tree")
    public AjaxResult categoryTree(ExamQbCategory examQbCategory)
    {
        return success(examQbCategoryService.selectCategoryTreeList(examQbCategory));
    }


    /**
     * 查询题库分类列表
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:category:list')")
    @GetMapping("/list")
    public AjaxResult list(ExamQbCategory examQbCategory)
    {
        List<ExamQbCategory> list = examQbCategoryService.selectExamQbCategoryList(examQbCategory);
        return success(list);
    }

    /**
     * 导出题库分类列表
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:category:export')")
    @Log(title = "题库分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamQbCategory examQbCategory)
    {
        List<ExamQbCategory> list = examQbCategoryService.selectExamQbCategoryList(examQbCategory);
        ExcelUtil<ExamQbCategory> util = new ExcelUtil<ExamQbCategory>(ExamQbCategory.class);
        util.exportExcel(response, list, "题库分类数据");
    }

    /**
     * 获取题库分类详细信息
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(examQbCategoryService.selectExamQbCategoryByCategoryId(categoryId));
    }

    /**
     * 新增题库分类
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:category:add')")
    @Log(title = "题库分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamQbCategory examQbCategory)
    {
        return toAjax(examQbCategoryService.insertExamQbCategory(examQbCategory));
    }

    /**
     * 修改题库分类
     */
   // @PreAuthorize("@ss.hasPermi('questionbank:category:edit')")
    @Log(title = "题库分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamQbCategory examQbCategory)
    {
        return toAjax(examQbCategoryService.updateExamQbCategory(examQbCategory));
    }

    /**
     * 删除题库分类
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:category:remove')")
    @Log(title = "题库分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(examQbCategoryService.deleteExamQbCategoryByCategoryIds(categoryIds));
    }
}
